package com.hy.erp.inventory.service ;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IBorrowTypeDao;
import com.hy.erp.inventory.pojo.BorrowType;
import com.hy.erp.inventory.pojo.MaterielOutBound.RepairAssistInfomation;
import com.hy.erp.inventory.pojo.interfaces.IArea;
import com.hy.erp.inventory.pojo.interfaces.IBorrowType;
import com.hy.erp.inventory.service.interfaces.IBorrowTypeService;

/**
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-28；时间：上午11:37:12</li>
 * <li>类型名称：BorrowTypeService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@ Name ( "borrowTypeService" )
@ Scope ( ScopeType.SESSION )
@ Stateless
public class BorrowTypeService
								extends
								AbstractBusinessService < IBorrowType >
																		implements
																		IBorrowTypeService
{

	/**
	 * <ul>
	 * <li>开发作者：李冰</li>
	 * <li>设计日期：2010-10-28；时间：上午11:38:05</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														3751806679774678750L ;

	@ Override
	public boolean addBorrowType (
									IBorrowType borrowType )
	{
		if ( null == borrowType )
		{
			return true ;
		}

		else
		{

			IBorrowTypeDao borrowTypeDao =
											( IBorrowTypeDao ) this
																	.getDao ( IBorrowType.class ) ;

			return borrowTypeDao
								.persist ( borrowType ) ;
		}
	}

	@ Override
	public boolean modifyBorrowType (
										IBorrowType borrowType )
	{

		if ( ( null == borrowType )
				|| ( null == borrowType
										.getIdentifier ( ) )
				|| ( borrowType
								.getIdentifier ( )
								.trim ( )
								.length ( ) == 0 ) )
		{
			return true ;
		}
		else
		{
			IBorrowTypeDao borrowTypeDao =
											( IBorrowTypeDao ) this
																	.getDao ( IBorrowType.class ) ;

			if ( null == borrowType )
			{
				throw new ArchitectureFoundationException (
															"修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}

			return ( borrowTypeDao
									.merge ( borrowType ) != null ) ;
		}

	}

	@ Override
	public Integer removeBorrowType (
										String [ ] borrowTypeIds )
	{
		if ( ( null == borrowTypeIds )
				|| ( borrowTypeIds.length == 0 ) )
		{
			return new Integer (
									0 ) ;
		}
		else
		{

			IBorrowTypeDao borrowTypeDao =
											( IBorrowTypeDao ) this
																	.getDao ( IBorrowType.class ) ;
			return borrowTypeDao
								.remove ( borrowTypeIds ) ;
		}

	}

	@ Override
	public String [ ] addBorrowType (
										Object [ ] borrowType )
	{

		if ( null == borrowType )
		{
			return null ;
		}

		else
		{

			IBorrowTypeDao borrowTypeDao =
											( IBorrowTypeDao ) this
																	.getDao ( IBorrowType.class ) ;
			
			BorrowType[] borrowTypes=new BorrowType[borrowType.length];
			for(int i=0;i<borrowType.length;i++)
			{
				BorrowType borrowType2=( BorrowType ) borrowType[i];
				borrowTypes[i]=borrowType2;
			}
			
			

			return borrowTypeDao
								.persist  ( borrowTypes ) ;
		}
	}

	@ Override
	public List < IArea > getAllArea ( )
	{
		IBorrowTypeDao borrowTypeDao =
			( IBorrowTypeDao ) this
									.getDao ( IBorrowType.class ) ;
return borrowTypeDao
.find ( );
	}

	@ Override
	public String [ ] modifyBorrowType (
											Object [ ] borrowType )
	{


		if ( null == borrowType )
		{
			return null ;
		}

		else
		{

			IBorrowTypeDao borrowTypeDao =
											( IBorrowTypeDao ) this
																	.getDao ( IBorrowType.class ) ;
			
			BorrowType[] borrowTypes=new BorrowType[borrowType.length];
			for(int i=0;i<borrowType.length;i++)
			{
				BorrowType borrowType2=( BorrowType ) borrowType[i];
				borrowTypes[i]=borrowType2;
			}
			
			

			return borrowTypeDao
								.merge   ( borrowTypes ) ;
		}
	
	}

}
